import { defHttp } from '@/utils/http/axios';
import { AxiosPromise } from 'axios';
import { CustomerVO, CustomerForm, CustomerQuery } from '@/api/customer/types';

/**
 * 查询客户信息列表
 * @param query
 * @returns {*}
 */

export const listCustomer = (query?: CustomerQuery): AxiosPromise<CustomerVO[]> => {
  return defHttp.get({
    url: '/customer/mast/list',
    params: query,
  });
};

/**
 * 查询客户信息详细
 * @param customerId
 */
export const getCustomer = (customerId: string): AxiosPromise<CustomerVO> => {
  return defHttp.get({
    url: '/customer/mast/' + customerId,
  });
};

/**
 * 新增客户信息
 * @param data
 */
export const addCustomer = (data: CustomerForm) => {
  return defHttp.post({
    url: '/customer/mast',
    data: data,
  });
};

/**
 * 修改客户信息
 * @param data
 */
export const updateCustomerFllow = (
  customerId: string | number,
  followIds: string | number | undefined,
) => {
  return defHttp.put({
    url: '/customer/mast/' + customerId + '/' + followIds,
  });
};

/**
 * 删除客户信息
 * @param customerId
 */
export const delCustomer = (customerId: string | number | Array<string | number>) => {
  return defHttp.delete({
    url: '/customer/mast/' + customerId,
  });
};

/**
 * 关注、取消关注客户
 * @param data
 */
export const updateCustomer = (data: CustomerForm) => {
  return defHttp.put({
    url: '/customer/mast',
    data: data,
  });
};

export function exportCustomer() {
  // 一定要加 responseType: 'blob'
  // 一定要加 responseType: 'blob'
  // 一定要加 responseType: 'blob'
  // 否则拿到的是string
  return defHttp.post<Blob>(
    { url: '/customer/mast/export', responseType: 'blob' },
    { isTransformResponse: false },
  );
}

/**
 * 新增客户地址
 * @param data
 */
export const addCustomerAddress = (data: any) => {
  return defHttp.post({
    url: '/customer/address',
    data: data,
  });
};

/**
 * 修改客户地址
 * @param data
 */
export const updateCustomerAddress = (data: any) => {
  return defHttp.put({
    url: '/customer/address',
    data: data,
  });
};

/**
 * 获取客户地址
 * @param query
 */
export const getCustomerAddress = (query?: CustomerQuery): AxiosPromise<CustomerVO[]> => {
  return defHttp.get({
    url: '/customer/address/list',
    params: query,
  });
};

/**
 * 删除客户地址
 * @param addressIds
 */
export const delCustomerAddress = (addressIds: Array<string | number>) => {
  return defHttp.delete({
    url: '/customer/address/' + addressIds,
  });
};

/**
 * 新增客户联系人
 * @param data
 */
export const addCustomerContact = (data: any) => {
  return defHttp.post({
    url: '/customer/contact',
    data: data,
  });
};

/**
 * 修改客户联系人
 * @param data
 */
export const updateCustomerContact = (data: any) => {
  return defHttp.put({
    url: '/customer/contact',
    data: data,
  });
};

/**
 * 查询客户联系人
 * @param customerId
 */
export const getCustomerContact = (query?: CustomerQuery): AxiosPromise<CustomerVO[]> => {
  return defHttp.get({
    url: '/customer/contact/list',
    params: query,
  });
};

/**
 * 删除客户联系人
 * @param contactIds
 */
export const delCustomerContact = (contactIds: Array<string | number>) => {
  return defHttp.delete({
    url: '/customer/contact/' + contactIds,
  });
};
